package cn.dankal.flyaudio.personal.notificaiton

import android.content.Intent
import android.view.View
import api.UserServiceFactory
import cn.dankal.basiclib.base.activity.BaseActivity
import cn.dankal.basiclib.rx.AbstractDialogSubscriber
import cn.dankal.business.pojo.NotifyCountBean
import cn.dankal.business.Constants.*
import cn.dankal.flyaudio.R
import kotlinx.android.synthetic.main.activity_notification.*

class NotificationActivity : BaseActivity() {
    override fun getLayoutId(): Int {
        return R.layout.activity_notification
    }

    override fun initComponents() {
        addSingleTitleBar("消息")

        cl_system_message.setOnClickListener {
            jump2List(MSG_TYPE_SYSTEM)
        }

        cl_appoint_message.setOnClickListener {
            jump2List(MSG_TYPE_APPOINT)
        }

        cl_comment_message.setOnClickListener {
            jump2List(MSG_TYPE_COMMENT)
        }

    }

    private fun jump2List(type: Int) {
        var intent = Intent(this@NotificationActivity, NotificationListActivity::class.java)
        intent.putExtra(TYPE, type)
        startActivity(intent)
    }

    override fun onResume() {
        super.onResume()
        checkoutCount()
    }
    private fun checkoutCount() {
        UserServiceFactory.message_list()
                .subscribe(object : AbstractDialogSubscriber<NotifyCountBean>(this) {
                    override fun onNext(t: NotifyCountBean) {
                        iv_appoint_tips.visibility= if(t.applyIsNew > 0)View.VISIBLE else View.GONE
                        iv_comment_tips.visibility= if(t.commentIsNew > 0)View.VISIBLE else View.GONE
                        iv_system_tips.visibility= if(t.systemIsNew > 0)View.VISIBLE else View.GONE
                    }
                })
    }

}
